package com.douqu.game.core.config.challenge;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author wangzhenfei
 *         2017-11-28 16:03
 */
public class ExpeditionConfig extends BattleInitConfig{
    /**道具奖励**/
    public GoodsData[] passReward;
    /**对话组别**/
    public String dialogue;
    /**BOSS军令回复速度**/
    public CommonData[] crystalGrow;
    /**关卡权重**/
    public String weight;
    public List<Integer> weightList = new ArrayList<>();

    @Override
    public boolean check()
    {
        if(passReward == null)
        {
            LogUtils.error("ExpeditionConfig check passReward is null -> id:" + id + " name:" + name);
            return false;
        }

        if(crystalGrow == null)
        {
            LogUtils.error("ExpeditionConfig check crystalGrow is null -> id:" + id + " name:" + name);
            return false;
        }

        return super.check();
    }


    @Override
    public boolean setVariable(String key, String value) {
        if("passReward".equals(key))
        {
            passReward = LoadUtils.loadGoodDataToArray(key, value);
            return LoadUtils.checkGoods(passReward, this.getClass(), key, id);
        }else if("weight".equals(key)){
            String [] w = value.split(ConstantFactory.SEMICOLON);
            for(String s : w){
                weightList.add(Integer.valueOf(s));
            }
            return true;
        }else if("crystalGrow".equals(key)){
            crystalGrow = LoadUtils.loadCommonDataToArray(key, value);
            return true;
        }
        else
            return super.setVariable(key, value);
    }


    @Override
    public String toString() {
        return "ExpeditionConfig{" +
                "passReward=" + Arrays.toString(passReward) +
                ", dialogue='" + dialogue + '\'' +
                ", crystalGrow=" + Arrays.toString(crystalGrow) +
                ", weight='" + weight + '\'' +
                ", weightList=" + weightList +
                "} " + super.toString();
    }
}
